<?php
namespace App\Models\Saas;

use App\Library\Tools;
use Illuminate\Database\Eloquent\Model;

/**
 * Class Auth
 * @package app\saas\model
 * 设置表
 */
class Setting extends Model
{
    protected $table = "saas_setting"; //表名
    const CREATED_AT = null;
    const UPDATED_AT = null;

    public static function transferField($data){
        if(!$data){
            return [];
        }
        $data = Tools::transferFields($data);
        return $data;
    }

    //获取多字段数据
    public static function getFields($field, $filter = [], $one = true, $toArray = true){ //缓存方法：缓存所有字段，只返回需要的字段
        if($one){
            $data = self::query()->where($filter)->select(is_array($field) ? $field : explode(",", $field))->first();
            return $data ? ($toArray ? self::transferField($data->toArray()) : Tools::transferFields($data->toArray())) : [];
        }else{
            $data = self::query()->where($filter)->select(is_array($field) ? $field : explode(",", $field))->get();
            return $data ? ($toArray ? self::transferField($data->toArray()) : $data) : [];
        }
    }
}